#include "ProtoUtil.h"
#include "ProtoFieldDescriptor.h"
#define WIRE_TAG_TYPE_BITS	3

namespace miniproto
{

const ::std::string EMPTY_STRING;

bool is_array_field(const uint8_t field_type)
{
	if ((field_type & ::miniproto::ProtoFieldDescriptor::ARRAY) > 0)
		return true;
	return false;
}

uint8_t base_field_type(const uint8_t field_type)
{
	return (field_type & 0x03F);
}

uint32_t wire_tag(const uint32_t number, const int32_t wire_type)
{
	return static_cast<uint32_t>((number << WIRE_TAG_TYPE_BITS) | wire_type);
}

void wire_tag_split(const uint32_t tag, uint32_t *number, int32_t *wire_type)
{
	*wire_type = (tag & 0x07);
	*number = (tag >> WIRE_TAG_TYPE_BITS);
}

int uint32_byte_size(const uint32_t val)
{
	if (val < (1 << 7)) {
		return 1;
	} else if (val < (1 << 14)) {
		return 2;
	} else if (val < (1 << 21)) {
		return 3;
	} else if (val < (1 << 28)) {
		return 4;
	} else {
		return 5;
	}
}

} // namespace miniproto
